package com.ruoyi.wms.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wms.domain.WmsProductstock;
import com.ruoyi.wms.service.IWmsProductstockService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品现存量Controller
 * 
 * @author chao
 * @date 2024-07-25
 */
@Controller
@RequestMapping("/wms/productstock")
public class WmsProductstockController extends BaseController
{
    private String prefix = "wms/productstock";

    @Autowired
    private IWmsProductstockService wmsProductstockService;

    @RequiresPermissions("wms:productstock:view")
    @GetMapping()
    public String productstock()
    {
        return prefix + "/productstock";
    }

    /**
     * 查询产品现存量列表
     */
    @RequiresPermissions("wms:productstock:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmsProductstock wmsProductstock)
    {
        startPage();
        List<WmsProductstock> list = wmsProductstockService.selectWmsProductstockList(wmsProductstock);
        return getDataTable(list);
    }

    /**
     * 导出产品现存量列表
     */
    @RequiresPermissions("wms:productstock:export")
    @Log(title = "产品现存量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmsProductstock wmsProductstock)
    {
        List<WmsProductstock> list = wmsProductstockService.selectWmsProductstockList(wmsProductstock);
        ExcelUtil<WmsProductstock> util = new ExcelUtil<WmsProductstock>(WmsProductstock.class);
        return util.exportExcel(list, "产品现存量数据");
    }

    /**
     * 新增产品现存量
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存产品现存量
     */
    @RequiresPermissions("wms:productstock:add")
    @Log(title = "产品现存量", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmsProductstock wmsProductstock)
    {
        return toAjax(wmsProductstockService.insertWmsProductstock(wmsProductstock));
    }

    /**
     * 修改产品现存量
     */
    @RequiresPermissions("wms:productstock:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WmsProductstock wmsProductstock = wmsProductstockService.selectWmsProductstockById(id);
        mmap.put("wmsProductstock", wmsProductstock);
        return prefix + "/edit";
    }

    /**
     * 修改保存产品现存量
     */
    @RequiresPermissions("wms:productstock:edit")
    @Log(title = "产品现存量", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmsProductstock wmsProductstock)
    {
        return toAjax(wmsProductstockService.updateWmsProductstock(wmsProductstock));
    }

    /**
     * 删除产品现存量
     */
    @RequiresPermissions("wms:productstock:remove")
    @Log(title = "产品现存量", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wmsProductstockService.deleteWmsProductstockByIds(ids));
    }
}
